package com.example.briandang;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_video);
		
		// mp4 -- works
		//playVideo("https://s3-us-west-1.amazonaws.com/bdang/demo/ads/prog/second_screen/coca_cola_mandarin.mp4");
		
		// 3gp -- works
		//playVideo("http://techslides.com/demos/sample-videos/small.3gp");
		
		// web m -- works
		//playVideo("http://techslides.com/demos/sample-videos/small.webm");
		
		// flv -- works
		//playVideo("http://techslides.com/demos/sample-videos/small.flv");
		
		// ogv -- DOES NOT WORK
		//playVideo("http://techslides.com/demos/sample-videos/small.ogv");
		
	}

	private void playVideo(String uri) 
	{
		VideoView vid = (VideoView) findViewById(R.id.videoView);
		
		// Set to Landscape orientation
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		
		Uri video = Uri.parse(uri);
		vid.setMediaController(new MediaController(this));
		vid.setVideoURI(video);
		vid.start();
		vid.requestFocus();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.video, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
